#ifndef __BM_DEBUG_H__
#define __BM_DEBUG_H__

#include "stdint.h"
#include "string.h"
#include "stdio.h"
#include "usart.h"
#include "timer.h"
extern uint8_t dbgBuffer[];

#define BM_LOG(format,args...) \
	do{\
		uint32_t now = get_tick()<<3;\
		(void)sprintf((char *)dbgBuffer, "[%5d.%03d][%4d]" format "\r\n", now/1000,now%100,__LINE__,## args);\
		UART_SEND(UART5,(uint8_t *)dbgBuffer, (uint16_t)strlen((char *)dbgBuffer));\
	}while(0)
	
#define BM_HEX(format,buf,len)\
	do{\
		uint32_t now = get_tick()<<3;\
		(void)sprintf((char *)dbgBuffer, "[%5d.%03d][%4d]" format ":", now/1000,now%100,__LINE__);\
		UART_SEND(UART5,dbgBuffer, (uint16_t)strlen((char *)dbgBuffer));\
		char* str0 = "\r\n00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\r\n"\
			         "---------------------------------------------------\r\n";\
		UART_SEND(UART5,(uint8_t*)str0, (uint16_t)strlen(str0));\
		for(int i=0;i<len;i++){\
			(void)sprintf((char *)dbgBuffer, "%02x ",buf[i]);\
			UART_SEND(UART5,dbgBuffer, 3);\
			if(i%16 == 15)\
				UART_SEND(UART5,(uint8_t *)"\r\n", strlen("\r\n"));\
		}\
		UART_SEND(UART5,(uint8_t *)"\r\n", strlen("\r\n"));\
	}while(0)


	
#endif
